package com.taobao.askwho.job;



import java.util.Date;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

public class BuildLuceneIndex {
	public static final Logger logger = Logger.getLogger(BuildLuceneIndex.class);
	public static void buildLuceneIndexBegin() {
		long time = System.currentTimeMillis();
		logger.info("构建索引->开始\t" + new Date());
		try {
			String url = "http://localhost:8983/solr/dataimport?command=full-import";
			HttpClient client = new HttpClient();
			PostMethod post = new PostMethod(url);
//			NameValuePair[] data = { new NameValuePair("Select1", "专利名称"),
//					new NameValuePair("Text1", "生活") };
//			post.setRequestBody(data);
			client.executeMethod(post);
			Header[] headers = post.getResponseHeaders();
			int statusCode = post.getStatusCode();
			logger.info("statusCode:" + statusCode);
			for (Header h : headers) {
				logger.info(h.toString());
			}
			String result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
			logger.info(result);
			logger.info("构建索引->结束" + (System.currentTimeMillis() - time));
		} catch (Exception e) {
			logger.error("创建索引出错->",e);
		}
	}

	public static void main(String[] args) {
		new BuildLuceneIndex().buildLuceneIndexBegin();
	}
}
